# coding=utf-8

"""object类"""


# 重写__str__方法来实现对实例对象的描述，__str__方法是object类自带的方法

class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __str__(self):  # 重写__str__方法
        return 'My name is {0}, I am {1}'.format(self.name, self.age)


stu = Student('Li Hua', 34)
print(stu)  # 默认调用__str__方法

"""多态的实现"""
"""Python语言不同于Java语言那样，Python语言关注的是动态语言，只需关心对象的行为"""


class A(object):
    def eat(self):
        print('eat apple')


class B(A):
    def eat(self):
        print('eat fruit')


class C(B):
    def eat(self):
        print('eat meat')


class D:
    def eat(self):
        print('drink mike')


def fun(obj):
    obj.eat()


fun(A())
fun(B())
fun(C())
fun(D())  # 只要类方法里有eat方法，就不用管是否继承了谁
